package spring.proxy;

import net.sf.cglib.proxy.Enhancer;

public class CglibBeanProxy {

    CglibBeanProxy() {
    }

    @SuppressWarnings("unchecked")
    public <T> T getProxyInstance(T originObject, Object... args) {
        if (args == null) {
            args = new Object[0];
        }
        Class<?>[] classes = new Class[args.length];
        for (int i = 0; i < args.length; i++) {
            classes[i] = args[i].getClass();
        }
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(originObject.getClass());
        enhancer.setCallback(new BeanHandler(originObject));
        return (T) enhancer.create(classes, args);
    }

}
